package greedy;

public class SolutionCandyDitribution135 {
    public static int candy(int[] ratings) {
        int[] records = new int[ratings.length];
        for (int i = 0; i < ratings.length; i++) {
            records[i] = 1;
            if (i >= 1 && ratings[i - 1] > ratings[i] && records[i - 1] <= records[i]) {
                for (int j = i; j >= 1 && ratings[j - 1] > ratings[j]; j--)
                    records[j - 1] = Math.max(records[j] + 1, records[j - 1]);
            } else if (i >= 1 && ratings[i - 1] < ratings[i])
                records[i] = records[i - 1] + 1;

        }
        int sum = 0;
        for (int i : records) {
            sum += i;
            System.out.print(i + ",");
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println("\n" + candy(new int[]{1,0,2}));
    }
}
